<?php 
require_once("/home/www/a.tttj.3z.cc/config.php");
require_once("/home/www/a.tttj.3z.cc/source/common.php");
require_once("/home/www/a.tttj.3z.cc/source/myfun.php");

$appid = 98;
$totalcash = 300;
$num = 1000;
$maxcash = 5;
$timeinfo = array('1030','1330','1830');

$timestr = date('Ymd');
$dblink = getdblink_tttj();

$sql = "select id from qhb_list where datestr=$timestr and appid=$appid limit 1";
$isexist = getonerecord_ps($sql,$dblink);
if ($isexist)
{
	exit;
}
	
foreach ($timeinfo as $time)
{
	$sql = "insert into tttj.qhb_list (left_num,datestr,opentime,appid) values ($num,$timestr,'$time',$appid)";
	exec_db_ps($sql,$dblink);
}	

$qhb_pool = array();
$leftcash = $totalcash*100 - 5*100;
$leftnum = $num;
for ($i=0;$i<1000;$i++)
{
	if ($i<50)
	{
		$cash = mt_rand(50,500);
	}else{
		$cash = mt_rand(1,100);
	}	
	if (($leftcash-$cash)/($leftnum-1)<1)
	{
		$tempcash = 500 - (($leftnum-1) - ($leftcash-$cash));
		$cash = $cash + $tempcash;
		$qhb_pool[] = $cash;
		for ($n=0;$n<$leftnum-1;$n++)
		{
			$qhb_pool[] = 1;
		}	
		break;
	}	
	$qhb_pool[] = $cash;
	$leftcash -= $cash;
	$leftnum --;
}	

foreach ($qhb_pool as $currcash)
{
	$currcash = $currcash/100;
	$sql = "insert into qhb_pool (daystr,cash,dstatus) values ($timestr,$currcash,1)";
	exec_db_ps($sql,$dblink);
}	
?>